package com.ledim.activity.base;

import android.widget.ListView;
import com.letv.android.young.client.R;
import com.ledim.widget.loadmore.LedimLoadMoreFooterView;
import com.ledim.widget.loadmore.LoadMoreContainer;
import com.ledim.widget.loadmore.LoadMoreHandler;
import com.ledim.widget.loadmore.LoadMoreListViewContainer;

/**
 * Created by ccx on 16/05/18.
 */
public abstract class LedimBaseListActivity<D> extends LedimBaseAdapterViewActivity<D, ListView> {

    @Override
    protected void initFooterView() {
        loadMoreContainer = findViewByIdExt(R.id.loadmore_view_container);
        if (enableLoadMoreRefresh()) {
            // TODO 改为自定义的footer,或者修改arr中默认footer添加loading progressbar
            LedimLoadMoreFooterView footerView = new LedimLoadMoreFooterView(this);
            loadMoreContainer.setLoadMoreView(footerView);
            footerView.setNeedFeedback(needFeedBack());
            loadMoreContainer.setAutoLoadMore(true);
            loadMoreContainer.setLoadMoreUIHandler(footerView);
            loadMoreContainer.setLoadMoreHandler(new LoadMoreHandler() {
                @Override
                public void onLoadMore(LoadMoreContainer loadMoreContainer) {
                    loadMore();
                }
            });
        }
    }

    @Override
    protected void loadMoreFinish(int errorCode, boolean hasMore) {
        loadMoreContainer.loadMoreFinish(errorCode, hasMore);
    }

    protected boolean needFeedBack() {
        return false;
    }
}
